from django.db import models

from django.contrib.auth.models import AbstractUser


class UserProfileModel(AbstractUser):
    """
    创建一个用户的模型
    """
    nick_name = models.CharField(max_length=50, verbose_name='昵称', null=False, default='')
    birthday = models.DateField(verbose_name='生日', null=True, blank=True)
    gender = models.CharField(max_length=20, choices=(('male', '男'), ('female', '女'), ('unknown', '保密')),
                              default='unknown', verbose_name='性别')
    address = models.CharField(max_length=100, default='', verbose_name='地址')
    mobile = models.CharField(max_length=11, null=True, blank=True, default='', verbose_name='手机号码')
    professional = models.CharField(max_length=50, default='', verbose_name='职业')
    company = models.CharField(max_length=20, default='', verbose_name='公司名字')
    person_introduction = models.CharField(max_length=200, default='', verbose_name='个人介绍')
    image = models.CharField(max_length=100, default='', verbose_name='头像')
    create_at = models.DateTimeField(auto_now_add=True, null=False, verbose_name='添加时间')
    update_at = models.DateTimeField(auto_now=True, null=False, verbose_name='修改时间')

    class Meta(object):
        verbose_name = '用户信息'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.username


class UserExtra(models.Model):
    """
    用户扩展模型
    """
    user = models.OneToOneField(to=UserProfileModel, on_delete=models.CASCADE, verbose_name='用户')
    blog_num = models.IntegerField(default=0, verbose_name='博客数')
    fans_num = models.IntegerField(default=0, verbose_name='粉丝数')
    like_num = models.IntegerField(default=0, verbose_name='喜欢数')
    comment_num = models.IntegerField(default=0, verbose_name='总评论数')
    level = models.IntegerField(default=0, verbose_name='级别')
    visit = models.IntegerField(default=0, verbose_name='访问量')
    integral = models.IntegerField(default=0, verbose_name='积分')
    ranking = models.IntegerField(default=0, verbose_name='排名')
    register_id = models.CharField(max_length=20, default='', verbose_name='用户注册ip')
    last_loigin_ip = models.CharField(max_length=20, default='', verbose_name='最后登录ip')
    create_at = models.DateTimeField(auto_now_add=True, null=False, verbose_name='添加时间')
    update_at = models.DateTimeField(auto_now=True, null=False, verbose_name='修改时间')

    class Meta(object):
        verbose_name = '用户扩展表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.user


class EmailVerifyRecordModel(models.Model):
    """
    创建一个邮箱验证码的模型
    """
    code = models.CharField(max_length=20, verbose_name='验证码')
    email = models.EmailField(max_length=50, verbose_name='邮箱')
    sent_type = models.CharField(max_length=20, choices=(('register', '注册'), ('forget', '忘记密码')), verbose_name='邮件类型',
                                 default='register')
    create_at = models.DateTimeField(auto_now_add=True, null=False, verbose_name='添加时间')
    update_at = models.DateTimeField(auto_now=True, null=False, verbose_name='修改时间')

    class Meta(object):
        verbose_name = '邮箱验证码'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.email
